//
//  TestWDCalendarViewController.m
//  MyDemos
//
//  Created by iMac on 2018/3/7.
//  Copyright © 2018年 iMac. All rights reserved.
//

#import "TestWDCalendarViewController.h"
#import "WDCalendarMonthScrollView.h"


@implementation TestWDCalendarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self addDismissButton];
    UILabel *showMonthLable = ({
        UILabel *lable = [[UILabel alloc] init];
        lable.frame = CGRectMake(0, 80, SCREEN_WIDTH, 20);
        lable.textColor = [UIColor blueColor];
        lable.font = [UIFont systemFontOfSize:14];
        lable;
    });
    [self.view addSubview:showMonthLable];
    
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat itemWidth = screenWidth / 7.0;
    CGFloat height = itemWidth * 5;
    WDCalendarMonthScrollView *scrollMonth = [[WDCalendarMonthScrollView alloc] initWithFrame:CGRectMake(0, 100, screenWidth, height)];
    scrollMonth.monthChange = ^(NSDate *firstDay) {
        NSLog(@"viewController - scrollMonth - firstDay: %@", firstDay);
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM"];
        showMonthLable.text = [formatter stringFromDate:firstDay];
    };
    [self.view addSubview:scrollMonth];
    
}


#pragma mark -添加dismissButton
- (void)addDismissButton {
    UIButton *dismiss = ({
        UIButton *btn = [[UIButton alloc] init];
        [btn setTitle:@"dismiss" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        CGFloat f = 100;
        btn.frame = CGRectMake(SCREEN_WIDTH - f, SCREEN_HEIGHT - f, f, f);
        [btn setBackgroundColor:[UIColor purpleColor]];
        [btn addTarget:self action:@selector(dismissButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        btn;
    });
    [self.view addSubview:dismiss];
}
- (void)dismissButtonClick:(UIButton *)sender {
    [self dismissViewControllerAnimated:true completion:nil];
}
@end
